Skip to content

Add namespaced resources #128#141

Closed
ricCap wants to merge 6 commits intocrossplane-contrib:mainfrom
ricCap:add-namespaced-resources
Closed

Add namespaced resources #128#141
ricCap wants to merge 6 commits intocrossplane-contrib:mainfrom
ricCap:add-namespaced-resources

Conversation

@ricCap
Copy link
Contributor

@ricCap ricCap commented Oct 23, 2025

Description of your changes

This is a first draft of the implementation of namespaced MRs #128 . This PR is a follow up to #139 and includes its changes. You can also have a look at the diff between the two branches here.

This PR includes:

  • adding namespaced resources and moving v1 resources to a different subfolder (cluster)
  • new resources are in the api group http.m.crossplane.io
  • adds e2e tests for new resources and adds to the Github Actions workflow jobs for running e2e tests with both crossplane v1 and v2
  • similar changes to crossplane v2: Generate namespace-scoped MRs provider-upjet-azure#1019 (comment) (I still need to verify that we match the description 1:1)
  • maybe to move to another PR - skip secret injection during deletion of resources (fixes deletion, all namespaced e2e tests can now be deleted using foreground deletion). You can test this using the example application below

The aim of this PR is to avoid any breaking changes to the existing resources

The changes are based on the following examples:

Warning There are some missing changes (e.g. the hack folder), this PR is still WIP but works and includes everything needed for the migration of the controllers. This PR is not ready to be merged yet.

We should do some refactoring as currently there is a lot of duplication. I would like to agree on how to structure the new repo and what to keep/change first. Since these changes are quite AI-driven, please point out things that don't make sense.

Fixes #128

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

  • e2e tests in the pipeline
  • deployed with argocd (foreground delete in ArgoCD works now as well)
image

Test in ArgoCD

Install using helm and use this application

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: provider-http-namespaced-examples
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/ricCap/provider-http
    targetRevision: add-namespaced-resources
    path: examples/namespaced
  destination:
    server: https://kubernetes.default.svc
    namespace: default
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
    - CreateNamespace=true

- Update crossplane-runtime from v1.20.0 to v2.0.0
- Implement missing interface methods for crossplane-runtime v2 compatibility:
  - Add GetUsers/SetUsers for UserCounter interface on ProviderConfig
  - Add GetItems for ProviderConfigUsageList interface
  - Add SetResourceReference/GetResourceReference for ProviderConfigUsage
- Add compile-time interface validation with var _ assignments
- Fix JQ expression syntax in e2e test examples:
  - Remove problematic outer parentheses from URL expressions
  - Fix Authorization header secret injection syntax
- Add interface casting tests to prevent runtime panics
- Update go.mod and go.sum for crossplane-runtime v2 dependencies
- Use chainsaw for e2e tests

Signed-off-by: Riccardo Capraro <capraroriccardo@gmail.com>
Key changes include:
- Complete API reorganization with cluster/ and namespaced/ separation
- Enhanced controller architecture with dual registration
- Comprehensive examples and documentation for both scopes
- Updated build configuration and CRD generation

All changes are backwards compatible

Signed-off-by: Riccardo Capraro <capraroriccardo@gmail.com>
…sues

- Fix DisposableRequest deletion logic to skip secret injection during deletion
- Fix cross-namespace owner reference validation in data-patcher to prevent errors
- Add unit tests for DisposableRequest namespaced controller
- Update example configuration to remove invalid setOwnerReference for cross-namespace secrets
- Add data-patcher tests for cross-namespace scenarios
- Fix secret name mismatch in request-with-clusterproviderconfig.yaml example

Signed-off-by: Riccardo Capraro <capraroriccardo@gmail.com>
- application/json
Authorization:
- ("Bearer {{ auth:default:token }}")
- "Bearer {{ auth:default:token }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

details, err := c.http.SendRequest(ctx, mapping.Method, requestDetails.Url, requestDetails.Body, requestDetails.Headers, cr.Spec.ForProvider.InsecureSkipTLSVerify)

// Skip secret injection during deletion to avoid cross-namespace owner reference issues
if !meta.WasDeleted(cr) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense? This was preventing resources from being deleted

ref := m.GetProviderConfigReference()

switch ref.Kind {
case "ProviderConfig":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part that was added to manage multiple provider configs

@arielsepton
Copy link
Member

Hey @ricCap! 👋

Thanks for tackling namespaced resources. Before moving forward with this PR, I want to share the direction I'm taking for the codebase architecture.

I'm working on a refactor that extracts the business logic into a service layer.
This refactor will decouple logic from resource types using interfaces

Once my refactoring merges you can add namespaced support on top of the shared service layer.

This way we maintain the codebase properly while still achieving your namespaced resources goal. The service layer will make your implementation cleaner and reduce the PR size significantly.

Let me know if you have questions about the approach!

@ricCap
Copy link
Contributor Author

ricCap commented Nov 17, 2025

Closing in favour of #147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Crossplane v2 and namespaced resources

2 participants